<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Category;
use App\Helper\Tree;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Widgets\Card;
use Dcat\Admin\Widgets\Tab;

class CategoryController extends AdminController
{

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Category(), function (Grid $grid)  {
            $grid->model()->orderByDesc("sort")->orderByDesc("id");
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('sort')->sortable();
            $grid->column('status')->using(['正常','隐藏'])->label(['info','default']);
            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();
            $grid->quickSearch(['name']);
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Category(), function (Form $form) {
            $form->text('name')->required();
            $form->number('sort')->default(0);
            $form->radio('status')->options(['正常','隐藏'])->default(0);
        });
    }
}
